<template>
  <el-drawer v-model="addDrawer" size="48%" :show-close="false" @opened="openDrawer" @close="closeDrawer">
    <template #title>
      <h2><svg-icon icon-class="list"></svg-icon><span style="padding-left: 15px">{{ formName }}</span></h2>
      <el-button type="primary" @click="confirmAndSave" :disabled="drawerLoading" v-if="!form[idName]">保存&继续填写</el-button>
      <el-button type="primary" @click="confirmClick" :disabled="drawerLoading" v-if="!(route.path.includes('dataIntegrate') || route.path.includes('achievementSearch'))">保存</el-button>
    </template>
    <template #default>
      <el-form :model="form" ref="addRef" :inline="true" :rules="formRules" label-width="160px">
        <el-row justify="space-between">
          <el-form-item label="省" prop="provinceId" v-if="provinceData.length > 0 || form.provinceId">
            <el-select v-model="form.provinceId" placeholder="请选择省" @change="chooseFormProvince" clearable>
              <el-option v-for="item in provinceData" :key="item.id" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="省" v-else>
            <el-input v-model="form.province" clearable disabled></el-input>
          </el-form-item>
          <el-form-item label="市" prop="cityId" v-if="provinceData.length > 0 || form.cityId">
            <el-select v-model="form.cityId" placeholder="请选择市" @change="chooseFormCity" clearable>
              <el-option v-for="item in cityData" :key="item.id" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="市" v-else>
            <el-input v-model="form.city" clearable disabled></el-input>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="区/县" prop="countyId" v-if="provinceData.length > 0 || form.countyId">
            <el-select v-model="form.countyId" placeholder="请选择区/县" @change="chooseFormCounty" clearable>
              <el-option v-for="item in areaData" :key="item.id" :label="item.name" :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="区/县" v-else>
            <el-input v-model="form.county" clearable disabled></el-input>
          </el-form-item>
          <el-form-item label="编号" prop="id">
            <el-input v-model="form.id" placeholder="请输入编号" clearable maxlength="17"></el-input>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="地质填图区编号" prop="mainAfsRegionId">
            <el-input v-model="form.mainAfsRegionId" placeholder="请输入地质填图区编号" clearable maxlength="17"></el-input>
          </el-form-item>
          <el-form-item label="目标区编号" prop="targetRegionId">
            <el-input v-model="form.targetRegionId" placeholder="请输入目标区编号" clearable maxlength="17"></el-input>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="工作区编号" prop="workRegionId">
            <el-input v-model="form.workRegionId" placeholder="请输入工作区编号" clearable maxlength="17"></el-input>
          </el-form-item>
          <el-form-item label="工程编号" prop="projectId">
            <el-input v-model="form.projectId" placeholder="请输入工程编号" clearable maxlength="17"></el-input>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="探测城市" prop="cityName">
            <el-input v-model="form.cityName" placeholder="请输入探测城市" clearable maxlength="20"></el-input>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="名称" prop="fileName" style="width: 100%">
            <el-input v-model="form.fileName" placeholder="请输入名称" clearable :autosize="{ minRows: 3, maxRows: 6 }"
              type="textarea" show-word-limit maxlength="200"></el-input>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="坐标系" prop="coordinateSystem" style="width: 100%">
            <el-input v-model="form.coordinateSystem" placeholder="请输入坐标系" clearable
              :autosize="{ minRows: 2, maxRows: 4 }" type="textarea" show-word-limit maxlength="50"></el-input>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="投影信息" prop="projection" style="width: 100%">
            <el-input v-model="form.projection" placeholder="请输入投影信息" clearable :autosize="{ minRows: 2, maxRows: 4 }"
              type="textarea" show-word-limit maxlength="50"></el-input>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="图件比例尺（分母）" prop="scale">
            <el-input v-model="form.scale" placeholder="请输入图件比例尺（分母）" clearable maxlength="4"></el-input>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="作者" prop="authors" style="width: 100%">
            <el-input v-model="form.authors" placeholder="请输入作者" clearable :autosize="{ minRows: 3, maxRows: 6 }"
              type="textarea" show-word-limit maxlength="100"></el-input>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="编制时间" prop="finishedTime" style="width: 100%">
            <!-- <el-input v-model="form.finishedTime" placeholder="请输入编制时间" clearable :autosize="{ minRows: 2, maxRows: 4 }" type="textarea" show-word-limit maxlength="50"></el-input> -->
            <el-date-picker v-model="form.finishedTime" type="date" placeholder="请选择编制时间" value-format="YYYY-MM-DD" />
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="使用资料记录" prop="materialRecord" style="width: 100%">
            <el-input v-model="form.materialRecord" placeholder="请输入使用资料记录" clearable
              :autosize="{ minRows: 4, maxRows: 8 }" type="textarea" show-word-limit maxlength="255"></el-input>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="资料/数据处理记录" prop="processingRecord" style="width: 100%">
            <el-input v-model="form.processingRecord" placeholder="请输入资料/数据处理记录" clearable
              :autosize="{ minRows: 4, maxRows: 8 }" type="textarea" show-word-limit maxlength="255"></el-input>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="出版单位" prop="publisher" style="width: 100%">
            <el-input v-model="form.publisher" placeholder="请输入出版单位" clearable :autosize="{ minRows: 3, maxRows: 6 }"
              type="textarea" show-word-limit maxlength="100"></el-input>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="出版日期" prop="publishDate" style="width: 100%">
            <!-- <el-input v-model="form.publishDate" placeholder="请输入出版日期" clearable :autosize="{ minRows: 2, maxRows: 4 }" type="textarea" show-word-limit maxlength="50"></el-input> -->
            <el-date-picker v-model="form.publishDate" type="date" placeholder="请选择出版日期" value-format="YYYY-MM-DD" />
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="图书在版编目（CIP）数据" prop="cip" style="width: 100%">
            <el-input v-model="form.cip" placeholder="请输入图书在版编目（CIP）数据" clearable :autosize="{ minRows: 5, maxRows: 10 }"
              type="textarea" show-word-limit maxlength="2147483647"></el-input>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="成果图图像文件编号" prop="resultMapAiid" style="width: 100%">
            <el-space direction="vertical" alignment="flex-start" :size="15" class="upload-space">
              <el-input v-model="form.resultMapAiid" placeholder="请输入成果图图像文件编号" clearable maxlength="20"></el-input>
              <ImageUpload v-model="form.resultMapAiidAttach" @uploadImage="uploadSuccess('resultMapAiidAttach', $event)"
                @delFile="deleteFile('resultMapAiidAttach', $event)" />
            </el-space>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="成果图原始档案文件编号" prop="resultMapArwid" style="width: 100%">
            <el-space direction="vertical" alignment="flex-start" :size="15" class="upload-space">
              <el-input v-model="form.resultMapArwid" placeholder="请输入成果图原始档案文件编号" clearable maxlength="20"></el-input>
              <FileUpload v-model="form.resultMapArwidAttach" @uploadFile="uploadSuccess('resultMapArwidAttach', $event)"
                @delFile="deleteFile('resultMapArwidAttach', $event)" />
            </el-space>
          </el-form-item>
        </el-row>
        <el-row justify="space-between">
          <el-form-item label="描述信息" prop="commentInfo" style="width:100%">
            <el-input v-model="form.commentInfo" placeholder="请输入描述信息" :autosize="{ minRows: 5, maxRows: 10 }"
              type="textarea" show-word-limit maxlength="2147483647" clearable></el-input>
          </el-form-item>
        </el-row>
      </el-form>
    </template>
  </el-drawer>
</template>
<script setup>
import { fourInt } from '@/utils/validate'
import useOtherData from '@/hooks/useOtherData'
const { route, form, queryData, formName, idName,
  uploadSuccess, deleteFile,
  chooseFormProvince, chooseFormCity, chooseFormCounty,
  addRef, confirmAndSave, addDrawer, confirmClick, checkIdValid, openDrawer, closeDrawer, drawerLoading } = useOtherData()

const { provinceData, cityData, areaData } = toRefs(queryData)

const formRules = reactive({
  provinceId: [{ required: true, message: '请选择省！', trigger: 'change' }],
  cityId: [{ required: true, message: '请选择市！', trigger: 'change' }],
  countyId: [{ required: true, message: '请选择区/县！', trigger: 'change' }],
  id: [
    { required: true, message: '请输入编号!', trigger: 'blur' },
    { min: 17, max: 17, message: '长度必须为17位', trigger: 'blur' },
    { validator: checkIdValid, trigger: 'blur' },
  ],
  cityName: [{ required: true, message: '请输入探测城市!', trigger: 'blur' }],
  fileName: [{ required: true, message: '请输入名称!', trigger: 'blur' }],
  scale: [fourInt]
})
</script>